home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / net / spakparnet_0_5.lha / snd / gfxthings.c < prev    next >
C/C++ Source or Header  |  1992-11-09  |  4KB  |  120 lines

  1. /********************************************************************
  2.  ** SAMPLE MANIPULATION PROGRAM
  3.  ** (c) Spak, Darrell Tam, c9107253@mystra.newcastle.edu.au (1993)
  4.  ** phone (Australia) 049-829-710
  5.  **                    49-829-710
  6.  ** (c) SST 1993
  7.  **
  8.  ** GENERIC + GRAPHICS ROUTINES
  9.  **
  10.  ** TABS to 4
  11.  ********************************************************************/
  12.  
  13. #include "everything.h"
  14. #include "sndthings.h"
  15.  
  16. /********************************************************************/
  17.         void FlushWindowInput(struct Window *wdw)
  18. /********************************************************************/
  19. {
  20. struct IntuiMessage *im;
  21.     while (im = (struct IntuiMessage *)GetMsg(wdw->UserPort))
  22.             ReplyMsg((struct Message *)im);
  23. }
  24.  
  25. /********************************************************************/
  26. void SaveCols(struct Window *wdw, USHORT *table, short n)
  27. /********************************************************************/
  28. {
  29. short i;
  30.     for(i = 0; i<n; i++)
  31.         *table++ = GetRGB4(wdw->WScreen->ViewPort.ColorMap,i);
  32. }
  33.  
  34.  
  35. /********************************************************************/
  36.             void ClearWindow(struct Window *wdw)
  37. /********************************************************************/
  38. {
  39. short    left = wdw->BorderLeft,
  40.         top = wdw->BorderTop,
  41.         width = wdw->Width-wdw->BorderRight,
  42.         height = wdw->Height-wdw->BorderBottom;
  43.  
  44.     if(width<1) width = 1;
  45.     if(height<1) height = 1;
  46.     SetDrMd(wdw->RPort, JAM1);
  47.     SetWrMsk(wdw->RPort, 0xff);
  48.     RectFill(wdw->RPort, left, top, width-1, height-1);
  49. }
  50.  
  51. /********************************************************************/
  52. void InvertBox(struct Window *wdw,
  53.         short x, short y, short w, short h, UBYTE mask)
  54. /********************************************************************/
  55. {
  56. short x1 = x, y1  = y, x2 = x+w, y2 = y+h;
  57.     if(x1 > x2) { x1 = x2; x2 = x; }
  58.     if(y1 > y2) { y1 = y2; y2 = y; }
  59.     SetDrMd(wdw->RPort, COMPLEMENT);
  60.     SetWrMsk(wdw->RPort, mask);
  61.     RectFill(wdw->RPort, x1, y1, x2, y2);
  62. }
  63.  
  64.  
  65. /********************************************************************/
  66. void DrawSample8Down(struct Window *wdw,
  67.             char *smpl, unsigned long smpllen,
  68.             short x, short y, short width, short height )
  69. /********************************************************************
  70.      Write an 8 bit sample into a window, with scaling and all
  71.              Should work with any sized sample now
  72.           Draw the sample scaled to fit on the screen
  73.  ********************************************************************/
  74. {
  75. short    mp;
  76. ULONG    scale;
  77.  
  78.     if(height<1 || width<1 || smpllen<1) return;
  79.     mp = (width>>1) + x;    /* mid point for the X axis */
  80.     scale = (width-2)<<8;    /* <<16 /256 for the X axis */
  81.  
  82. /** DRAW A SCALED SAMPLE THING FROM LINES (ITS BIGGER THAN OUR DISPLAY WINDOW) */
  83.     if(height < smpllen) {
  84.     UWORD    i, l, s, fracstep, fraccounter = 0;
  85.     ULONG    counter = 0, intstep;
  86.         intstep = smpllen / height;
  87.         fracstep = ((smpllen % height)<<16) / height;
  88.         for(i = y+height, l = y; l < i; l++)
  89.         {
  90.             s = (smpl[counter]*scale)>>16;
  91.             Move(wdw->RPort, mp-s, l);
  92.             Draw(wdw->RPort, mp+s, l);
  93.             counter += intstep;
  94.             if(fraccounter > (fraccounter += fracstep)) counter++;
  95.         }
  96.     } else {
  97.  
  98. /** DRAW THE SAMPLE AS IT REALLY IS (ITS SMALLER THAN OUR DISPLAY WINDOW) */
  99.     UWORD    i, l, s;
  100.     ULONG    step, counter = 0;
  101.  
  102.         step = (height<<16)/smpllen;    /* height is in pixels (<<65k) so ok */
  103.         Move(wdw->RPort, mp+(s=((*smpl++)*scale)>>16), y);
  104.         counter = (y<<16) + step;
  105.         Draw(wdw->RPort, mp+s, l = (counter>>16)-1);
  106.         for(i = 1; i < smpllen; i++) {
  107.             Draw(wdw->RPort,
  108.                 mp+(s=((*smpl++)*scale)>>16), l);
  109.             counter += step;
  110.             Draw(wdw->RPort, mp+s, l = (counter>>16)-1);
  111.         }
  112.     }
  113. }
  114.  
  115.  
  116. /*    for(k = 0, s = 0, j = counter>>16; j < (counter+step)>>16; j++, k++)
  117.             s += ABS(smpl[j]); if(k<1) k = 1; s = ((s/k) * scale) >> 16; */
  118.  
  119.  
  120.